<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="java.util.*,javax.naming.*,java.sql.*,javax.sql.*"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		Context ctx = new InitialContext();
		String strLookup = "java:comp/env/jdbc/test";
		DataSource ds = (DataSource) ctx.lookup(strLookup);
		Connection con = ds.getConnection();

		if (con != null) {
			out.println("success<br>");
			String sql = "select * from users";
			PreparedStatement ps = con.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			
			while (rs.next()) {
				out.println(String.format("name: %s, password: %s<br>", rs.getString("name"), rs.getString("password")));
			}
			
			rs.close();
			ps.close();
			con.close();
		} else {
			out.println("failure<br>");
		}
	%>

</body>
</html>